package com.chanceit.ssss.adapters;

import org.gl.utils.lg;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.chanceit.ssss.activity.R;
import com.chanceit.ssss.data.DataSources;
import com.chanceit.ssss.fragments.BaseFragment;
import com.chanceit.ssss.fragments.BusinessListFragment;
import com.chanceit.ssss.fragments.CarExceptionListFragment;
import com.chanceit.ssss.fragments.CarHitListFragment;
import com.chanceit.ssss.fragments.CarerListFragment.OnListFragmentSelectedListener;
import com.chanceit.ssss.fragments.CarerLostListFragment;

public class SafeTabPagerAdapter extends FragmentStatePagerAdapter implements
		OnListFragmentSelectedListener {
	Activity context;
	String tabs[] ;;
	Fragment[] fagments ;
	final static public int[] icons = new int[] {R.drawable.ic_hit, R.drawable.ic_excepiton,
			R.drawable.ic_falut, R.drawable.ic_scby,
			R.drawable.ic_bxdq, R.drawable.ic_bydq, R.drawable.ic_bxiandq,
			R.drawable.ic_njdq, R.drawable.ic_zhxc, };//FIXME 修改车辆碰撞的图标

	public SafeTabPagerAdapter(FragmentManager fm, Activity context) {
		super(fm);
		this.context = context;
		tabs = new String[] {"车辆碰撞",
				context.getString(R.string.tab_title_yichangcanshu),
				context.getString(R.string.tab_title_cheliangguzhang), };
		fagments = new Fragment[tabs.length];
	}
	public Fragment[] getFagments() {
		return fagments;
	}
	// 当前车速,发送机转速,电瓶电压,冷却液温度,发动机负载,节气门位置,大气压,进气歧管绝对压力,空气流量,环境空气温度,进气温度,OBD协议,OBD标准,燃油量
	@Override
	public Fragment getItem(int position) {
		Fragment fragment = fagments[position];
		if (fragment == null) {
			switch (position) {
			case 2:
				fragment = new CarExceptionListFragment(
						DataSources.BusinessType_canshuyichang, position);// 参数异常
				fagments[position] = fragment;// FIXME
				break;
			case 1:
				fragment = new BusinessListFragment(
						DataSources.BusinessType_cheliangguzhang, position);// 车辆故障
				fagments[position] = fragment;
				break;
			case 0:
				fragment = new CarHitListFragment(
						DataSources.BusinessType_pengzhuangtixing, position);// 碰撞提醒
				fagments[position] = fragment;
				break;
			default:
				fragment = new CarHitListFragment(
						DataSources.BusinessType_pengzhuangtixing, position);// 碰撞提醒
				fagments[position] = fragment;
				break;
			}
		}
		return fragment;
	}

	@Override
	public int getCount() {
		return tabs.length;
	}

	@Override
	public CharSequence getPageTitle(int position) {
		return tabs[position];
	}

	String TAG = "SectionPagerAdpater";

	public void sendMessage(int postion) {
		if (fagments[postion] != null
				&& fagments[postion] instanceof BaseFragment) {
			((BaseFragment) fagments[postion]).receiveMessage(null);
		} else {
			lg.e(TAG,
					"Exception,the fragment is null,or not BaseFragment ,so it can not receive message,");
		}
	}

	@Override
	public void onArticleSelected(int position) {

	}
}